<template>
    <el-table :data="tableData" border stripe :header-cell-class-name="headerBg"
              @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="reid" label="reid" ></el-table-column>
        <el-table-column prop="id" label="id" ></el-table-column>
        <el-table-column prop="name" label="用户" ></el-table-column>
        <el-table-column prop="college" label="学院" ></el-table-column>
        <el-table-column prop="major" label="专业" ></el-table-column>
        <el-table-column prop="term" label="学期" ></el-table-column>
        <el-table-column prop="applytime" label="申请时间" ></el-table-column>
        <el-table-column prop="ispass" label="进度"></el-table-column>
        <el-table-column label="审核" width="350">
            <template v-slot="scope">
                <el-button type="success" @click="terntodetail(scope.row)" :disabled="scope.row.ispass !== '待审核'">数据详情</el-button>
                <el-button type="success" @click="changeState(scope.row, '审核通过...师傅正在赶来的路上')" :disabled="scope.row.ispass !== '待审核'">审核通过</el-button>
                <el-button type="danger" @click="changeState(scope.row, '审核不通过')" :disabled="scope.row.ispass !== '待审核'">审核不通过</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-dialog title="详情" v-model="dialogVisible">
        <el-form :model="stuss">
            <el-input placeholder="reid" v-model="stuss.reid" type="text" disabled/>
            <el-input placeholder="学号" v-model="stuss.stuid" type="text" disabled/>
            <el-input placeholder="姓名" v-model="stuss.stuname" type="text" disabled/>
            <el-input placeholder="学院" v-model="stuss.stucollege" type="text" disabled />
            <el-input placeholder="专业" v-model="stuss.stumajor" type="text" disabled/>
            <el-input placeholder="所在学期" v-model="stuss.term" type="text" disabled/>
            <el-input placeholder="留级原因" v-model="stuss.detail" type="textarea" resize="none" :rows="3" disabled />
            <el-button type="warning" @click="dialogVisible=false">取消</el-button>
        </el-form>
    </el-dialog>
</template>
<script setup>
import { get,post } from '@/utils/request.js'
import {ElMessage} from 'element-plus'
import { ref,onMounted } from 'vue'
import moment from 'moment';
import { reactive } from 'vue'

const dialogVisible=ref(false)
const tableData=ref([])
const datas=ref([])
const index=ref(0)
const types=ref('')
const stuss = reactive({
reid:'',
stuid:'',
stuname:'',
stucollege:'',
stumajor:'',
term:'',
detail:''
})

onMounted(async () => {
   init();
})

const init=()=>{
 get('/repetition/check',(message)=>{
   tableData.value   = message.map(item=>({
    ...item,
     applytime: moment(item.applytime).format('YYYY-MM-DD'),
    }))
})
}

const terntodetail=(row)=>{
post('/repetition/detail',{
reid:row.reid
},(message)=>{
dialogVisible.value=true
stuss.reid=message.reid
stuss.stuid=message.id
stuss.stuname=message.name
stuss.stumajor=message.major
stuss.stucollege=message.college
stuss.term=message.term
stuss.detail=message.detail
},(message)=>{
ElMessage.warning(message)
})
}

 const changeState=(row, state)=> {

if(state=='审核通过...师傅正在赶来的路上'){
post('/repetition/checksuccess',{reid:row.reid,id:row.id,term:row.term},(message)=>{
init()
ElMessage.success(message)
},(message)=>{
ElMessage.warning(message)
})
}else{
post('/repetition/checkfailure',{reid:row.reid},(message)=>{
init()
ElMessage.success(message)
},(message)=>{
ElMessage.warning(message)
})
}
      this.form = JSON.parse(JSON.stringify(row))
      this.form.state = state;
      this.save();
    }
</script>
<style scoped>
</style>